use crate::config;
use crate::oidc::OidcClient;
use crate::support::error::AppResult;
use crate::{oidc, server};
use axum::Router;

#[derive(Clone)]
pub struct AppState {
    pub oidc_client: OidcClient,
}
impl AppState {
    fn new(oidc_client: OidcClient) -> Self {
        Self { oidc_client }
    }
}
pub async fn run(router: Router<AppState>) -> AppResult<()> {
    server::logger::init();
    tracing::info!("Starting application...");
    let oidc_client = oidc::init().await?;
    let state = AppState::new(oidc_client);
    let server = server::Server::new(config::get().server_config());
    server.start(state, router).await?;
    Ok(())
}